<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>日记分组</title>
    <link rel="stylesheet" type="text/css" href="/bootstrap-3.4.1-dist/css/bootstrap.css">
    <style>
        .right {
            padding: 40px;
        }

        a {
            color: white;
            text-decoration: none;
        }

        a:hover {
            color: white;
            text-decoration: none;
        }
    </style>
    <script type="text/javascript" src="/script/jquery.min.1.10.2.js"></script>
    <script type="text/javascript">

    </script>
</head>
<body>
<!--第三部分-->
<div class="right">
    <a href="/group/insertPage">
        <button class="btn btn-success" style="margin-bottom: 40px" id="z_xy">
            新增日记分组
        </button>
    </a>
    <table class="table table-hover">
        <thead>
        <tr class="info">
            <th>分组id</th>
            <th>分组名称</th>
            <th>分组日记个数</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="g:${groupList}">
            <td th:text="${g.id}"></td>
            <td th:text="${g.name}"></td>
            <td th:text="${g.dcount}"></td>
            <td>
                <script type="text/javascript" th:inline="javascript">
                    var deleteDiary = function (id) {
                        $.ajax({
                            type: 'GET',
                            url: "/group/delete",
                            data: {
                                "id": id,
                            },
                            success: function (data) {
                                if (data.code === 5000) {
                                    alert(data.msg);
                                } else {
                                    alert(data.msg);
                                    location.href = "http://localhost:8080/group/groupDetail"
                                }
                            }
                        })
                    }
                </script>
                <button class="btn btn-danger" th:onclick="deleteDiary([[${g.id}]])">删除</button>
                <a th:href="@{/group/updatePage(id=${g.id})}">
                    <button class="btn btn-warning">
                        修改
                    </button>
                </a>
            </td>
        </tr>
        </tbody>
    </table>
</div>
</body>
</html>
